package com.bedrock.project.inside.api.v1;

import com.bedrock.common.utils.DateUtils;
import com.bedrock.common.utils.poi.ExcelUtil;
import com.bedrock.framework.aspectj.lang.annotation.Log;
import com.bedrock.framework.aspectj.lang.enums.BusinessType;
import com.bedrock.framework.web.controller.BaseController;
import com.bedrock.framework.web.domain.AjaxResponse;
import com.bedrock.framework.web.domain.AjaxResult;
import com.bedrock.framework.web.page.TableDataInfo;
import com.bedrock.project.inside.entity.WorkHourStat;
import com.bedrock.project.inside.service.IWorkHourStatService;
import com.bedrock.project.inside.vo.request.WorkHourStatReqVo;
import com.bedrock.project.inside.vo.response.ProjectStatResVo;
import com.bedrock.project.inside.vo.response.SaleStatResVo;
import com.bedrock.project.inside.vo.response.UserStatResVo;
import com.bedrock.project.inside.vo.response.WorkHourStatResVo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 工时统计Controller
 * @author toby.zhang
 * @date 2020-04-30
 */
@RestController
@RequestMapping("/work_hour/stat")
public class WorkHourStatController extends BaseController
{
    @Autowired
    private IWorkHourStatService workHourStatService;

    /**
     * 查询工时统计列表
     */
    @PreAuthorize("@ss.hasPermi('work_hour:stat:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkHourStat workHourStat)
    {
        startPage();
        List<WorkHourStat> list = workHourStatService.selectWorkHourStatList(workHourStat);
        return getDataTable(list);
    }

    /**
     * 导出工时统计列表
     */
    @PreAuthorize("@ss.hasPermi('work_hour:stat:export')")
    @Log(title = "工时统计", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WorkHourStat workHourStat)
    {
        List<WorkHourStat> list = workHourStatService.selectWorkHourStatList(workHourStat);
        ExcelUtil<WorkHourStat> util = new ExcelUtil<WorkHourStat>(WorkHourStat.class);
        return util.exportExcel(list, "stat");
    }

    /**
     * 获取工时统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('work_hour:stat:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(workHourStatService.selectWorkHourStatById(id));
    }

    /**
     * 新增工时统计
     */
    @PreAuthorize("@ss.hasPermi('work_hour:stat:add')")
    @Log(title = "工时统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkHourStat workHourStat)
    {
        return toAjax(workHourStatService.insertWorkHourStat(workHourStat));
    }

    /**
     * 修改工时统计
     */
    @PreAuthorize("@ss.hasPermi('work_hour:stat:edit')")
    @Log(title = "工时统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkHourStat workHourStat)
    {
        return toAjax(workHourStatService.updateWorkHourStat(workHourStat));
    }

    /**
     * 删除工时统计
     */
    @PreAuthorize("@ss.hasPermi('work_hour:stat:remove')")
    @Log(title = "工时统计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(workHourStatService.deleteWorkHourStatByIds(ids));
    }

    /**
     * 工时统计-每天跑一次
     */
    public void workHourStat(){
        logger.info("工时统计任务：{}", DateUtils.getNowDate());
        workHourStatService.workHourStatisticsByDay();
    }

    /**
     * 项目维度工时报表统计列表
     */
    @ApiOperation("获取项目维度工时报表统计列表 -- toby.zhang")
    @ApiImplicitParams({
            @ApiImplicitParam(name="searchValue",value="查询值.项目名称",dataType="String",  required = false ,paramType = "query",example="内部管理系统"),
            @ApiImplicitParam(name="startTime",value="开始时间",dataType="String",  required = false ,paramType = "query",example="2020-05-01"),
            @ApiImplicitParam(name="endTime",value="结束时间",dataType="String",  required = false ,paramType = "query",example="2020-05-06"),
    })
    //@PreAuthorize("@ss.hasPermi('work_hour:stat:list')")
    @GetMapping("/projectStatList")
    public TableDataInfo<ProjectStatResVo> projectStatList(WorkHourStatReqVo workHourStatReqVo)
    {
        startPage();
        List<ProjectStatResVo> list = workHourStatService.selectProjectStatList(workHourStatReqVo);
        return getDataTable(list);
    }

    /**
     * 工时维度工时报表统计图表-饼状图/折线图
     */
    @ApiOperation("工时维度工时报表统计图表-饼状图/折线图 -- toby.zhang")
    @ApiImplicitParams({
            @ApiImplicitParam(name="searchType",value="查询类型.2:工时维度-饼图;3:工时维度-折线图;",dataType="String", required = true,paramType = "query",example="1"),
            @ApiImplicitParam(name="searchValue",value="查询值.项目名称",dataType="String",  required = false ,paramType = "query",example="内部管理系统"),
            @ApiImplicitParam(name="startTime",value="开始时间",dataType="String",  required = false ,paramType = "query",example="2020-05-01"),
            @ApiImplicitParam(name="endTime",value="结束时间",dataType="String",  required = false ,paramType = "query",example="2020-05-06"),
    })
    //@PreAuthorize("@ss.hasPermi('work_hour:stat:list')")
    @GetMapping("/workHourStatList")
    public AjaxResponse workHourStatList(WorkHourStatReqVo workHourStatReqVo)
    {
        return AjaxResponse.success(workHourStatService.selectWorkHourStatChart(workHourStatReqVo));
    }

    /**
     * 个人维度工时报表统计列表
     */
    @ApiOperation("获取个人维度工时报表统计列表 -- toby.zhang")
    @ApiImplicitParams({
            @ApiImplicitParam(name="searchValue",value="查询值.员工姓名",dataType="String",  required = false ,paramType = "query",example="admin"),
            @ApiImplicitParam(name="startTime",value="开始时间",dataType="String",  required = false ,paramType = "query",example="2020-05-01"),
            @ApiImplicitParam(name="endTime",value="结束时间",dataType="String",  required = false ,paramType = "query",example="2020-05-06"),
    })
    //@PreAuthorize("@ss.hasPermi('work_hour:stat:list')")
    @GetMapping("/userStatList")
    public TableDataInfo<UserStatResVo> userStatList(WorkHourStatReqVo workHourStatReqVo)
    {
        startPage();
        List<UserStatResVo> list = workHourStatService.selectUserStatList(workHourStatReqVo);
        return getDataTable(list);
    }

    /**
     * 销售维度工时报表统计列表
     */
    @ApiOperation("获取销售维度工时报表统计列表 -- toby.zhang")
    @ApiImplicitParams({
            @ApiImplicitParam(name="searchValue",value="查询值.销售员姓名",dataType="String",  required = false ,paramType = "query",example="张三"),
            @ApiImplicitParam(name="startTime",value="开始时间",dataType="String",  required = false ,paramType = "query",example="2020-05-01"),
            @ApiImplicitParam(name="endTime",value="结束时间",dataType="String",  required = false ,paramType = "query",example="2020-05-06"),
    })
    //@PreAuthorize("@ss.hasPermi('work_hour:stat:list')")
    @GetMapping("/saleStatList")
    public TableDataInfo<SaleStatResVo> saleStatList(WorkHourStatReqVo workHourStatReqVo)
    {
        startPage();
        List<SaleStatResVo> list = workHourStatService.selectSaleStatList(workHourStatReqVo);
        return getDataTable(list);
    }

    /**
     * 导出项目维度工时报表统计列表
     */
    @ApiOperation("导出项目维度工时报表统计列表 -- toby.zhang")
    @ApiImplicitParams({
            @ApiImplicitParam(name="searchValue",value="查询值.项目名称",dataType="String",  required = false ,paramType = "query",example="内部管理系统"),
            @ApiImplicitParam(name="startTime",value="开始时间",dataType="String",  required = false ,paramType = "query",example="2020-05-01"),
            @ApiImplicitParam(name="endTime",value="结束时间",dataType="String",  required = false ,paramType = "query",example="2020-05-06"),
    })
    //@PreAuthorize("@ss.hasPermi('work_hour:stat:export')")
    @Log(title = "导出项目维度工时报表统计列表", businessType = BusinessType.EXPORT)
    @GetMapping("/exportProjectStatList")
    public AjaxResult exportProjectStatList(WorkHourStatReqVo workHourStatReqVo)
    {
        List<ProjectStatResVo> list = workHourStatService.selectProjectStatList(workHourStatReqVo);
        ExcelUtil<ProjectStatResVo> util = new ExcelUtil<ProjectStatResVo>(ProjectStatResVo.class);
        return util.exportExcel(list, "工时报表-项目");
    }

    /**
     * 导出工时维度工时报表统计列表
     */
    @ApiOperation("导出工时维度工时报表统计列表 -- toby.zhang")
    @ApiImplicitParams({
            @ApiImplicitParam(name="searchValue",value="查询值.项目名称",dataType="String",  required = false ,paramType = "query",example="内部管理系统"),
            @ApiImplicitParam(name="startTime",value="开始时间",dataType="String",  required = false ,paramType = "query",example="2020-05-01"),
            @ApiImplicitParam(name="endTime",value="结束时间",dataType="String",  required = false ,paramType = "query",example="2020-05-06"),
    })
    //@PreAuthorize("@ss.hasPermi('work_hour:stat:export')")
    @Log(title = "工时维度工时报表统计列表", businessType = BusinessType.EXPORT)
    @GetMapping("/exportWorkHourStatList")
    public AjaxResult exportWorkHourStatList(WorkHourStatReqVo workHourStatReqVo)
    {
        List<WorkHourStatResVo> list = workHourStatService.selectWorkHourStatDetail(workHourStatReqVo);
        ExcelUtil<WorkHourStatResVo> util = new ExcelUtil<WorkHourStatResVo>(WorkHourStatResVo.class);
        return util.exportExcel(list, "工时报表-工时");
    }

    /**
     * 导出个人维度工时报表统计列表
     */
    @ApiOperation("导出个人维度工时报表统计列表 -- toby.zhang")
    @ApiImplicitParams({
            @ApiImplicitParam(name="searchValue",value="查询值.员工姓名",dataType="String",  required = false ,paramType = "query",example="admin"),
            @ApiImplicitParam(name="startTime",value="开始时间",dataType="String",  required = false ,paramType = "query",example="2020-05-01"),
            @ApiImplicitParam(name="endTime",value="结束时间",dataType="String",  required = false ,paramType = "query",example="2020-05-06"),
    })
    //@PreAuthorize("@ss.hasPermi('work_hour:stat:export')")
    @Log(title = "导出个人维度工时报表统计列表", businessType = BusinessType.EXPORT)
    @GetMapping("/exportUserStatList")
    public AjaxResult exportUserStaList(WorkHourStatReqVo workHourStatReqVo)
    {
        List<UserStatResVo> list = workHourStatService.selectUserStatList(workHourStatReqVo);
        ExcelUtil<UserStatResVo> util = new ExcelUtil<UserStatResVo>(UserStatResVo.class);
        return util.exportExcel(list, "工时报表-个人");
    }

    /**
     * 导出销售维度工时报表统计列表
     */
    @ApiOperation("导出销售维度工时报表统计列表 -- toby.zhang")
    @ApiImplicitParams({
            @ApiImplicitParam(name="searchValue",value="查询值.销售员姓名",dataType="String",  required = false ,paramType = "query",example="张三"),
            @ApiImplicitParam(name="startTime",value="开始时间",dataType="String",  required = false ,paramType = "query",example="2020-05-01"),
            @ApiImplicitParam(name="endTime",value="结束时间",dataType="String",  required = false ,paramType = "query",example="2020-05-06"),
    })
    //@PreAuthorize("@ss.hasPermi('work_hour:stat:export')")
    @Log(title = "导出销售维度工时报表统计列表", businessType = BusinessType.EXPORT)
    @GetMapping("/exportSaleStatList")
    public AjaxResult exportSaleStatList(WorkHourStatReqVo workHourStatReqVo)
    {
        List<SaleStatResVo> list = workHourStatService.selectSaleStatList(workHourStatReqVo);
        ExcelUtil<SaleStatResVo> util = new ExcelUtil<SaleStatResVo>(SaleStatResVo.class);
        return util.exportExcel(list, "工时报表-销售");
    }

}
